<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<form>
    <p>
        <input type="file" name="upload_img">
    </p>
    <p>
        <input type="text" name="user">
    </p>
    <button>提交</button>
</form>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
let form = document.querySelector('form')

form.onsubmit = function (e){
    // 阻止表单提交
    e.preventDefault()

    // 创建FormData对象
    let fd = new FormData(form)

    // 使用axios提交
    axios.post('http://localhost:8080/goods/upload',fd,{
        headers: {
            // 发送FormData数据时，会自动设置这个请求头
            'Content-Type': 'multipart/form-data'
        }
    })
    .then((res)=>{
        console.log( res )
    })
    .catch((err)=>{
        console.log( err )
    })
}

</script>

</body>
</html>